<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>密码框验证信息</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        div {
            width: 600px;
            margin: 100px auto;
        }
        
        .message {
            display: inline-block;
            font-size: 12px;
            color: #999;
            background: url(./ok.png) no-repeat left center;
            padding-left: 20px;
        }
        
        .warn {
            color: red;
            background: url(./warn.png) no-repeat left center;
        }
    </style>
</head>

<body>
    <p>采取calssName的修改来实现</p>
    <div class="register">
        <input type="password" class="ipt">
        <p class="message">请输入6~16为密码</p>
    </div>

</body>
<script>
    //获取元素
    let ipt = document.querySelector('.ipt');
    let p = document.querySelector('.message');
    //失去焦点事件
    ipt.onblur = function() {
        console.log('失去焦点');
        //根据表单里面值的长度 ipt.value.length  来判断
        if (ipt.value.length <= 16 && ipt.value.length >= 6) {
            p.className = 'message';
            p.innerHTML = 'ok';
        } else {
            p.className = 'message warn'; //多类名 保留message类中的属性  并新增warn中的属性 
            p.innerHTML = '你输入的密码长度错误，请输入6~16为密码';
        }
    }
</script>

</html>